/*
** 2726.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Sun Oct 12 13:14:48 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/
/* #include "2726.h" */
/*
 * EXPERIENCE: no two xxxx with the same D and C, but same D or same
 *             C is possible....
 *             needs a small linked list
 */
#include <stdio.h>

int main()
{
     int N, D, C;
     int dis[10001], cost[10001], rank[10001];
     int i, drank, crank;
     int min, min_rank;
     
     for(i = 1; i < 10001; i++)
	  dis[i] = cost[i] = rank[i] = 0;
     
     scanf("%d", &N);
     for(i = 1; i <= N; i++){
	  scanf("%d%d", &D, &C);
	  dis[D] = i;
	  cost[C] = i;
     }
     scanf("%d", &i);		/* discard the ending '0' */
     
     for(i = drank = crank = 1; i <= 10000; i++){
	  if (dis[i])
	       rank[dis[i]] += drank++;
	  if (cost[i])
	       rank[cost[i]] += crank++;
     }

     for(i = 1, min = min_rank = 20001; i <= N; i++)
	  if (rank[i] < min_rank){
	       min_rank = rank[i];
	       min = i;
	  }

     printf("%d\n", min);

     return 0;
}

